package org.infodavid.common.model;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.infodavid.common.IBuilder;
import org.infodavid.common.ejb.DocumentBean;
import org.infodavid.common.model.components.IOwnerDetails.EVisibility;

/**
 * The Class DocumentTest.
 */
public class DocumentTest extends AbstractBeanTest<IDocument> {

	/** The user test. */
	private final UserTest userTest = new UserTest(this);

	/**
	 * Instantiates a new document test.
	 * @param mainTest the main test
	 */
	@SuppressWarnings("rawtypes")
	public DocumentTest(final AbstractBeanTest mainTest) {
		super(mainTest);
	}

	/**
	 * Instantiates a new document test.
	 */
	public DocumentTest() {
		super();
	}

	/**
	 * Populate.
	 * @param count the count
	 * @return the collection< test data>
	 * @throws Exception the exception
	 */
	@Override
	protected List<IDocument> doCreate(final int count) throws Exception {
		final IBuilder<IDocument> builder = ModelFactory.getInstance().getBuilder(IDocument.class);
		final Iterator<IUser> users = userTest.populate(count).iterator();
		final List<IDocument> items = new ArrayList<IDocument>(count);
		IDocument item;
		IUser user;

		for (int i = 0; i < count; i++) {
			item = builder.create();
			user = users.next();

			item.setArchived(false);
			item.setName("item-" + System.nanoTime());
			item.setMimeType("text/plain");
			item.getOwnerDetails().setVisibility(EVisibility.GROUP);
			item.getOwnerDetails().setUser(user);
			item.getOwnerDetails().setGroup(user.getPrimaryGroup());

			items.add(item);
		}

		return items;
	}

	/**
	 * See super class or interface. (non-Javadoc)
	 * @see org.infodavid.common.model.AbstractBeanTest#getEntityClass()
	 */
	@Override
	public Class<DocumentBean> getEntityClass() {
		return DocumentBean.class;
	}

	/**
	 * See super class or interface. (non-Javadoc)
	 * @see org.infodavid.common.model.AbstractBeanTest#getEntityName()
	 */
	@Override
	public String getEntityName() {
		return IDocument.class.getSimpleName();
	}
}
